package com.example.test;

import com.example.util.SleepUtils;

import java.util.concurrent.locks.LockSupport;

import static com.example.util.SleepUtils.sleep;

public class Main01 {

    public static void main(String[] args) {

        Worker worker=new Worker();
        worker.start();

//        sleep(2);
//        LockSupport.unpark(worker);
        worker.unlock();
    }


    public static class Worker extends Thread{

        @Override
        public void run() {
            SleepUtils.sleep(4);
            while (true){
                System.out.println("begin lock");
//                lock();
                LockSupport.parkNanos(1000*1000*1000L);
                System.out.println("end lock");
            }
        }

        private void lock(){
            LockSupport.parkNanos(1000);
//            LockSupport.park();
        }

        public void unlock(){
            LockSupport.unpark(this);
        }
    }
}
